package com.qcdp.config;

import com.qcdp.dto.UserDTO;
import com.qcdp.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从线程局部变量当中获取用户信息
        UserDTO user = UserHolder.getUser();
        if(user == null){
            response.setStatus(401);
            return  false;
        }
        //6.放行
        return true;
    }
}
